var _util = require('util/util.js')
var vue = require('./../common/vue')
const { toHandlerKey } = require('vue');
const _other_service = require('service/other-service');

//创建vue对象
var shop_content = new vue({
    el: "#shop_content",
    //定义数据
    data: {
        shopArray: [
            {
                name: "卷王服装店",
                sellername: "海波",
                salesvolume: 111,
                faviorablerate: 4.6,
                address: "浙江绍兴",
                available: 1
            },
            {
                name: "卷王服装店",
                sellername: "波",
                salesvolume: 111,
                faviorablerate: 4.6,
                address: "浙江绍兴",
                available: 1
            },
            {
                name: "卷王服装店",
                sellername: "海",
                salesvolume: 111,
                faviorablerate: 4.6,
                address: "浙江绍兴",
                available: 1
            }
        ],
        //搜索框关键字
        search_seller : "",
        search_shop : "",
        /*
            修改启用状态
            edit_sellername: 当前操作的用户名
            available: 是否启用
         */
        edit_shopname : "",
        available: "",
        /*
            分页查询参数 1!5!
         */
        pagesize: 5,
        pageid: 1,
    },
    methods: {
        //查询所有的店铺(分页)
        search: function () {
            _other_service.getShopsBy(shop_content.pagesize,shop_content.pageid,shop_content.search_shop,shop_content.search_sellername,
                function (res) {
                    data.sellerArray = res;
                },
                function (err) {
                    console.log(err);
                })
        },
        //设置店铺是否禁用
        setavailable : function(index){
            console.log("点击了账号禁用");
            this.edit_shopname = this.shopArray[index].name;
            this.editavailable = this.shopArray[index].available;
            _other_service.modifyShopStatus(
                shop_content.edit_sellername,
                shop_content.editavailable,
                function(res) {
                    alert("修改店铺状态成功");
                },
                function(err) {
                    alert("修改店铺状态失败");
                }
            )
        },
        deleteShopAccount: function (index){
            this.edit_shopname = this.shopArray[index].name;
            _other_service.deleteShop(
                shop_content.edit_sellername,
                function(res) {
                    alert("店铺删除成功");
                },
                function(err) {
                    alert("店铺删除失败");
                }
            )
        },
        resetSearchInfo : function(){
            this.search_seller = "请输入卖家名";
            this.search_shop = "请输入店铺名";
        }
    },
    //初始化vue对象，渲染数据
    created: function () {
        _other_service.getAllSeller(shop_content.pagesize, shop_content.pageid,
            function (res) {
                shop_content.data.shopArray = res.data;
            },
            function (res) {
                console.log("渲染数据错误")
            }
        );
    },
});
